// banner 滚动 渲染 js
var swiper = new Swiper('.banner', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    spaceBetween: 0,
    centeredSlides: true,
    autoplay: false,
    autoplayDisableOnInteraction: false,
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev'

});

// 合作伙伴 滚动 js 
var swiper2 = new Swiper('.partners-list', {
    spaceBetween: 10,
    speed: 4000,
    simulateTouch: false,
    slidesPerView: 6,
    autoplay: 1,
    loop: true,
    freeMode: false,
    slidesPerGroup: 1,
});

// in stop out play
$('.list-wrapper').hover(function () {
    swiper2.stopAutoplay();
}, function () {
    swiper2.startAutoplay();
})

let crimp1 = $('.exhibition').offset().top - $(".exhibition").height();
let crimp2 = $('.about-us').offset().top - $(".about-us").height();
let crimp3 = $('.produc').offset().top - $(".produc").height();;
let crimp4 = 120;
let crimp5 = 120;
let exhibitionIn = true;
let aboutContent = true;
let produc = true;
let header = true;

$(window).scroll(function () {
    if ($(window).scrollTop() > 670 && header) {
        $('header').addClass('fixed');
        header = false;
    }
    else if ($(window).scrollTop() > crimp1 && exhibitionIn) {
        $('.exhibition').find('li').addClass('active');
        exhibitionIn = false;
    }
    else if ($(window).scrollTop() > crimp2 && aboutContent) {
        $('.about-content').addClass('active');
        aboutContent = false;
    }
    else if ($(window).scrollTop() > crimp3 && produc) {
        let icheck = $('.produc-ul').find("li").length;
        let idom = $('.produc-ul').find("li");
        let i = 0;
        let timer = setInterval(function () {
            $(idom[i]).addClass("current");
            i++;
            if (i >= icheck) {
                window.clearInterval(timer);
            }
        }, 400)
        $('.produc-ul').addClass('active');
        produc = false;
    }
    else {
        if (!header && $(window).scrollTop() < 670) {
            $('header').removeClass('fixed');
            header = true;
        }
        if (!exhibitionIn && $(window).scrollTop() < crimp1) {
            $('.exhibition').find('li').removeClass('active');
            exhibitionIn = true;
        }
        if (!aboutContent && $(window).scrollTop() < crimp2) {
            $('.about-content').removeClass('active');
            aboutContent = true;
        }
        if (!produc && $(window).scrollTop() < crimp3) {
            $('.produc-ul').find('li').removeClass('current');
            produc = true;
        }
    }
})

// class exhibition 区域  效果;
$('.exhibition').find('li').hover(function () {
    $(this).addClass('touch');
}, function () {
    $(this).removeClass('touch');
})

// class produc  产品&业务 效果
$('.produc').find('li').hover(function () {
    $(this).addClass('active');
}, function () {
    $(this).removeClass('active');
})

$('.news-content').on('click','.news-big-item',function(){
    window.location.href="news.html?listIndex="+$(this).index();
})

// 接口业务

let IndexController = {
    createNewsList: function (page, pagesize) {
        let bearingBox = $('.news-list .news-content');
        let newsDom = '';
        $.ajax({
            url: uilts.URL+'news/page',
            dataType: 'json',
            data: { 'pageNum': page, 'pageSize': pagesize },
            type: 'GET',
            success: function (res) {
                let newsListArray = res.data.list;
                let newsDateTime = {};
                let objectEl = {};
                for (let i = 0, length = newsListArray.length - 1; i <= length; i++) {
                    objectEl = newsListArray[i];
                    newsDateTime = uilts.formatDateTime(objectEl.releaseDate);
                    console.log(i<=0)
                    if (i == 0) {
                        newsDom += '<div class="news-big-item is-big">' +
                            '<dl>' +
                            '<dt>' +
                            '<div class="date-icon">' +
                            '<span>19</span><p>' +
                            '2018.07' +
                            '</p></div>' +
                            '<p>《24T智能电梯管理运营平台》项目鉴定会</p>' +
                            '</dt>' +
                            '<dd class="text text-overflow">上海市电梯行业协会于2018年7月19日在上海组织并主持了上海乐配信息科技有限公司开发完成的《24T智能电梯管理运营平台》项目鉴定会。鉴定委员会由朱昌明、支锡凤等七位专家、教授组成。</dd>' +
                            '</dl>' +
                            '<img src="news_images/1-4.jpg" alt="" class="big-img">' +
                            '</div>';
                    }
                    else if (i == 1){
                        newsDom += '<div class="news-big-item">' +
                            '<dl class="min-w">' +
                            '<dt>' +
                            '<div class="date-icon">' +
                            '<span>10</span><p>' +
                            '2018.05'+
                        '</p></div>' +
                            '</dt>' +
                            '<dd class="text">' +
                            '<p class="is-small">海安县申菱电器制造有限公司精彩亮相2018中国国际电梯展览会</p>' +
                            '<p class="is-small-p text-overflow">2018中国国际电梯展览会于5月8日至11日在上海国家会展中心盛大开幕。中国国际电梯展览会汇聚了全球电梯产业的精粹，是世界上最大规模的电梯展览会。作为江苏省高新技术企业的海安县申菱电器制造有限公司（以下简称“申菱电器”）再次精彩亮相本届展会。</p>' +
                            '</dd>' +
                            '</dl>' +
                            '</div>';
                    }
                    else if (i == 2){
                        newsDom += '<div class="news-big-item">' +
                            '<dl class="min-w">' +
                            '<dt>' +
                            '<div class="date-icon">' +
                            '<span>10</span><p>' +
                            '2018.02'+
                            '</p></div>' +
                            '</dt>' +
                            '<dd class="text">' +
                            '<p class="is-small">凝心聚力、锐意进取、再创辉煌 | 海安县申菱电器制造有限公司迎新年会</p>' +
                            '<p class="is-small-p text-overflow">2018年2月9日晚上17:58分，海安县申菱电器制造有限公司“凝心聚力、锐意进取、再创辉煌”迎新年会暨优秀员工颁奖盛典拉开帷幕。</p>' +
                            '</dd>' +
                            '</dl>' +
                            '</div>';
                    }
                }
                bearingBox.append(newsDom)
            },
            complete: function () { },
            error: function () { }
        })
    }
}



IndexController.createNewsList(1, 3);